#! /usr/bin/env python3

import sys

# check the number of arguments given to the script

if len(sys.argv)!=2:
	sys.stderr.write("Usage: %s FILENAME\n" %sys.argv[0])
	sys.exit(1)

# open the provided file and load its content

f = open(sys.argv[1])
text = f.read()
f.close()

# prepare the rows to be sorted

rows = text.split('\n')
rows.pop()
rows.pop(0)

# sort the rows of the provided file

finishings = list(filter(lambda row: ">" not in row, rows))
finishings.sort(key=lambda row: 600*float(row.split(';')[-3])+float(row.split(';')[-6]))
timeouts = list(filter(lambda row: ">" in row, rows))
timeouts.sort(key=lambda row:float(row.split(';')[-3]))

# print the rows in sorted order

for row in finishings:print(row)
for row in timeouts: print(row)